package crp.services.api.graphql.models;

import crp.core.resource.domain.models.Attachment;
import crp.core.resource.domain.models.AttachmentType;
import com.qwlabs.storage.models.StorageObject;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import org.eclipse.microprofile.graphql.Ignore;
import org.eclipse.microprofile.graphql.Type;

import javax.validation.constraints.NotNull;
import java.util.List;

@Type("Attachment")
@Builder
@Getter
@AllArgsConstructor
public class AttachmentPayload {
    @NotNull
    private final AttachmentType type;
    @Ignore
    private final List<StorageObject> items;

    public static AttachmentPayload of(Attachment attachment) {
        return AttachmentPayload.builder()
                .type(attachment.getType())
                .items(attachment.getItems())
                .build();
    }
}
